# Maintainer: Laurent Carlier <lordheavym@archlinux.org>
# Contributor: damir <damir@archlinux.org>
# Contributor: TheHoff <forums>

pkgname=devil
pkgver=1.8.0
pkgrel=8
pkgdesc="Library for reading several different image formats"
arch=('loong64' 'x86_64')
url="https://sourceforge.net/projects/openil/"
depends=('libpng' 'jasper' 'lcms2' 'libjpeg-turbo')
makedepends=('cmake')
options=('!docs' '!emptydirs')
license=('GPL')
source=(https://downloads.sourceforge.net/openil/DevIL-$pkgver.tar.gz
        soversion.patch
        jasper.patch)
sha256sums=('0075973ee7dd89f0507873e2580ac78336452d29d34a07134b208f44e2feb709'
            'f6ef4b428fd68f0fb837af548d20ffa5ca96f3e8e4f57faca8f5a90dc48b0377'
            'a3e1009e70be5a159250e3ea30d39f5aef1fa23eacece79e72deda51d7200159')

prepare() {
  cd "${srcdir}/DevIL"

  # Add solib version number to CMakeLists.txt
  # https://github.com/DentonW/DevIL/pull/50
  patch -Np1 -i "${srcdir}/soversion.patch"
  # https://github.com/DentonW/DevIL/commit/42a62648e727e9a0217280474546de3ac69cbff1
  patch -Np1 -i "${srcdir}/jasper.patch"
}

build() {
  cd "${srcdir}/DevIL/DevIL"

  rm -rf build && mkdir build
  cd build
  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib
  make  
}

package() {
  cd "${srcdir}/DevIL/DevIL/build"

  make DESTDIR="$pkgdir" install
}
